#include "stringutil.h"

std::wstring s2ws(std::string str , int CodePage  )  
{  
#if (TARGET_OS == OS_WINDOWS)

	std::wstring result;
	int len = MultiByteToWideChar(CodePage, 0, str.c_str(), str.size(), NULL, 0);
	WCHAR* buffer = ALLOC_NEW WCHAR[len + 1];
	MultiByteToWideChar(CodePage, 0, str.c_str(), str.size(), buffer, len);
	buffer[len] = '\0';
	result.append(buffer);
	delete[] buffer;
	return result;

#endif // #if (TARGET_OS == OS_WINDOWS)

	return L"";
}  
  
std::string ws2s(std::wstring wstr , int CodePage )  
{  
#if (TARGET_OS == OS_WINDOWS)
	std::string result;  
	int len = WideCharToMultiByte(CodePage, 0, wstr.c_str(), wstr.size(), NULL, 0, NULL, NULL);  
	char* buffer = ALLOC_NEW char[len + 1];
	WideCharToMultiByte(CodePage, 0, wstr.c_str(), wstr.size(), buffer, len, NULL, NULL);  
	buffer[len] = '\0';  
	result.append(buffer);  
	delete[] buffer;  
	return result;  
#endif // #if (TARGET_OS == OS_WINDOWS)

	return "";
} 



